package org.ljy.forum6.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.ljy.forum6.exception.ApplicationException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "用户测试接口")
@RequestMapping("/test")
@RestController
public class TestController {





    @ApiOperation("测试接口1,显示hello World")
    @GetMapping("/hello")
    public String hello() {
        return "Hello World";
    }


    /**
     * 异常测试
     * @return
     * @throws Exception
     */
    @ApiOperation("测试接口2,显示抛出的异常信息")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是⼀个Exception");
    }
    @ApiOperation("测试接口3,显示自定义的异常信息")
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }

    @ApiOperation("测试接口4,显示用户传的参数")
    @GetMapping("/helloByName")
    public String helloByName(@ApiParam("要传入的姓名") @RequestParam("name") String name) {
        return "Hello " + name;
    }
}
